package com.kingschan.jeasytag.sql.parse.fieldtype;

import org.json.JSONObject;
import com.kingschan.jeasytag.sql.parse.AbstractAnalysis;
import com.kingschan.util.lang.StringUtil;
/**
 *NumberboxAnalysis
 * @author kingschan
 *date:2013-4-24
 */
public class NumberboxAnalysis extends AbstractAnalysis{

	private String generic(JSONObject filter) throws Exception{
		String operactor=AbstractAnalysis.Operator.get(filter.getString("Operator"));
		StringBuffer sb = new StringBuffer();
		if ("".equals(StringUtil.ConvertNullStr(filter.getString("value")))) {
			return "";
		}
		if (operactor.equals("Contain")||operactor.equals("likeLeft")||operactor.equals("likeRight")) {
			return "";
		}	
		
		sb.append(filter.getString("filterfield")).append("\t");
		 if(operactor.equals("in")){
			sb.append(" in (").append(StringUtil.convertStrToSqlInstr(filter.getString("value"), true)).append(")");
		}else{
			sb.append(operactor).append(filter.getString("value"));
		}
		return sb.toString();
		
	}
	@Override
	protected String mysqlAnalysis(JSONObject filter) throws Exception {		
		return this.generic(filter);
	}

	@Override
	protected String oracleAnalysis(JSONObject filter) throws Exception {
		return this.generic(filter);
	}

	@Override
	protected String sqlserverAnalysis(JSONObject filter) throws Exception {		
		return this.generic(filter);
	}

}
